package com.cares.event.dao.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import cn.sh.cares.dao.orm.hibernate.query.SafeDetachedCriteria;
import cn.sh.cares.dao.orm.hibernate.query.SafeRestrictions;

import com.cares.common.dao.impl.JsflowDaoImpl;
import com.cares.event.dao.EventProcessDao;
import com.cares.event.entity.TEventProcess;

@Repository("eventProcessDao")
public class EventProcessDaoImpl extends JsflowDaoImpl implements
		EventProcessDao {
	
	/**
	 * 查询流程
	 * @param jsflowProcessVO
	 */
	public List<TEventProcess> queryEventProcess(String eventClass, String state){
		
		SafeDetachedCriteria criteria = SafeDetachedCriteria.forClass(TEventProcess.class);
		if(StringUtils.isNotBlank(eventClass)){
			criteria.add(SafeRestrictions.equal("jsflowClass", eventClass));
		}
		if(StringUtils.isNotBlank(state)){
			criteria.add(SafeRestrictions.equal("state", state));
		}
		return getEntityManager().queryForListByCriteria(TEventProcess.class, criteria);
	}

	/**
	 * 查询流程
	 * @param 主键
	 */
	public TEventProcess getEventProcess(Long id){
		return getEntityManager().get(TEventProcess.class, id);
	}
	
	/**
	 * 保存流程
	 * @param jsflowProcessVO
	 */
	public void saveEventProcess(TEventProcess tEventProcess){
		getEntityManager().save(tEventProcess);
	}
	
	/**
	 * 更新流程
	 * @param jsflowProcessVO
	 */
	public void updateEventProcess(TEventProcess tEventProcess){
		getEntityManager().update(tEventProcess);
	}

}
